//录面板
var gridPanel;
//表单窗口
var contentPanel;
//单面板
var formPanel;
//页面布局管理器
var viewport = null;
//服务处理标志
var processFlag = false;

Date.prototype.toString=function(){ 
  return this.format("Ymd"); 
};

var configFormWindow;
var configFormPanel;
var batchAddFormWindow;
var batchAddFormPanel;
var uploadFormWindow;
var uploadFormPanel;
var envType = '';

//格式化日期  
function formatDate(value) {  
    if (Ext.isEmpty(value)) {//判断是否是日期类型的数据  
        return '';  
    } else {  
        if (Ext.isDate(value)){  
        	alert("1  "+value+"  "+Ext.util.Format.date(value, 'Ymd'));
            return ""+Ext.util.Format.date(value, 'Ymd');// 用于时间控件返回值  
        }
        else  {  
        	alert("2  "+value+"  "+Ext.util.Format.date(new Date(value), 'Ymd'));
            return Ext.util.Format.date(new Date(value), 'Ymd');// 转换为Date类型  
        }
    }  
} 

var recordDef = Ext.data.Record.create([{name:'code'},{name:'name'}]);
var dataStore = new Ext.data.Store({
	proxy:new Ext.data.HttpProxy({url:'/getAllEnviroments'}),
	reader:new Ext.data.JsonReader({id:'code',root:'comboBox'},recordDef),
	remoteStore:true
});
var dataStore1 = new Ext.data.Store({
	proxy:new Ext.data.HttpProxy({url:'/getAllEnviroments?excludeAll=true'}),
	reader:new Ext.data.JsonReader({id:'code',root:'comboBox'},recordDef),
	remoteStore:true	
});
var projectDataStore = new Ext.data.Store({
	proxy:new Ext.data.HttpProxy({url:'/getApplications'}),
	reader:new Ext.data.JsonReader({id:'code',root:'comboBox'},recordDef),
	remoteStore:true
});
var projectDataStore1 = new Ext.data.Store({
	proxy:new Ext.data.HttpProxy({url:'/getApplications?excludeAll=true'}),
	reader:new Ext.data.JsonReader({id:'code',root:'comboBox'},recordDef),
	remoteStore:true
});


//创建活动面板
function createGridPanel(){
	//检查对象是否已经创建
	if( gridPanel!=null ) return;
	//设置数据源
	var ds = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({url:systemContext + '/appconfig/page'}),
		reader: new Ext.data.JsonReader({
			root: 'records',
			totalProperty: 'total',
			id: 'configId'
			},
			['appId','configId','appName','envType','configKey','configValue','createTime','isEncrypt','memo','serverIp','type','updateTime','version']
		)
	});

	//列选择模式
	var sm = new Ext.grid.CheckboxSelectionModel();
	//列表名
	var colModel = new Ext.grid.ColumnModel([        
        new Ext.grid.RowNumberer({header:"序号",width:30}),
        sm,
        {header:"配置ID",dataIndex:"configId",width:50},
        {header:"应用代码",dataIndex:"appId",width:60},
        {header:"应用名称",dataIndex:"appName",width:140},
        {header:"环境",dataIndex:"envType",width:80,renderer:function(value){
        	if( value=='dev'){
        		return '开发环境';
        	}else if( value=='test'){
        		return '测试环境';
        	}else if( value=='stat'){
        		return '预发布环境';
        	}else if( value=='prod'){
        		return '预发布环境';
        	}else{
        		return '其他';
        	}
        }},
        {header:"配置键",dataIndex:"configKey",width:340,editor: new Ext.form.TextField({allowBlank: false})},
        {header:"配置值",dataIndex:"configValue",width:160,editor: new Ext.form.TextField({allowBlank: false})},
        {header:"版本",dataIndex:"version",width:40,editor: new Ext.form.TextField({allowBlank: false})},
        {header:"所属IP",dataIndex:"ip",width:70,editor: new Ext.form.TextField({allowBlank: false})},
        {header:"类型",dataIndex:"type",width:40,renderer:function(value){
        	if( value=='S'){
        		return '系统';
        	}else {
        		return '业务';
        	}
        },editor: new Ext.form.ComboBox({
		     store: new Ext.data.SimpleStore({
				    fields: ['returnValue', 'displayValue'],
				    data : [['S','系统'], ['B','业务']]
				}),
			    displayField:'displayValue',
			    valueField:'returnValue',
			    typeAhead: true,
			    mode: 'local',
			    editable:false,
			    triggerAction: 'all',
			    emptyText:'类型',
			    selectOnFocus:true,
			    fieldLabel : '类型',
			    hiddenName:'type',
				name : 'type',
				allowBlank : false,
			})},
        {header:"是否加密",dataIndex:"isEncrypt",width:70,renderer:function(value){
        	if( value=='1'){
        		return '是';
        	}else {
        		return '否';
        	}
        },editor: new Ext.form.ComboBox({
		     store: new Ext.data.SimpleStore({
				    fields: ['returnValue', 'displayValue'],
				    data : [['0','否'], ['1','是']]
				}),
			    displayField:'displayValue',
			    valueField:'returnValue',
			    typeAhead: true,
			    mode: 'local',
			    editable:false,
			    triggerAction: 'all',
			    emptyText:'是否加密',
			    selectOnFocus:true,
			    fieldLabel : '是否加密',
			    hiddenName:'isEncrypt',
				name : 'isEncrypt',
				allowBlank : false,
			})},
        {header:"备注",dataIndex:"memo",width:100,editor: new Ext.form.TextField({allowBlank: false})},
        {header:"创建时间",dataIndex:"createTime",width:120,editor: new Ext.form.TextField({allowBlank: false})},
        {header:"修改时间",dataIndex:"updateTime",width:120,editor: new Ext.form.TextField({allowBlank: false})}
    ]);
	colModel.defaultSortable = true;
	//创建grid面板
	gridPanel = new Ext.grid.EditorGridPanel({
			border:false,
			buttonAlign :'left',
			loadMask: true,
			store: ds,
			autoExpandColumn:7,
			height:'100%',
			autoWidth:false,
			cm: colModel,
			sm: sm,
			autoScroll: true,
			tbar: ['环境：',{xtype:'tbseparator'},new Ext.form.ComboBox({
				    store: dataStore,
				    displayField:'name',
				    valueField:'code',
				    typeAhead: true,
				    mode: 'remote',
				    editable:false,
				    hiddenName:'envType',
					width:70,
				    triggerAction: 'all',
				    emptyText:'全部',
				    selectOnFocus:true,
					anchor:'80%',
					name : 'envType',
					listeners: {
			            select: function(combo, record, index) {
			            	envType = combo.getValue();
			            	projectDataStore.removeAll();
			            	projectDataStore.load({params:{envType: envType}});
			            }
			        }
				}),
				'应用：',{
					xtype : 'combo',
					store : projectDataStore,
					displayField : 'name',
					valueField : 'code',
					typeAhead : true,
					mode : 'remote',
					triggerAction : 'all',
					width: 200,
					emptyText : '请选应用...',
					selectOnFocus : true,
					resizable : true,
					hiddenName : 'appId',
					listeners:{
						focus:function(combo,record,index){
							projectDataStore.load({params:{envType: Ext.get('envType').dom.value}});
			            }
			        }
				},{xtype:'tbseparator'},
				'配置键：',{xtype:'textfield',width:80,id:'configKey',name:'configKey'},{xtype:'tbseparator'},
				'配置值：',{xtype:'textfield',width:80,id:'configValue',name:'configValue'},{xtype:'tbseparator'},
				'版本：',{xtype:'textfield',width:35,id:'version',name:'version'},{xtype:'tbseparator'},
				{text:'搜索',iconCls:'icon-search',handler:function(){
					ds.load({
				    	params:{start:0, limit:50}
				    });
				}},{xtype:'tbseparator'},
				{text:'添加配置',iconCls:'rec_add',handler:function(){
					configFormWindow.show();
				}},{xtype:'tbseparator'},
				{text:'批量添加配置',iconCls:'rec_batch',handler:function(){
					batchAddFormWindow.show();
				}},{xtype:'tbseparator'},
				{text:'保存配置',iconCls:'rec_save',handler:function(){
					if( ds.getCount()==0 ) {
						Ext.MessageBox.alert('提示','无记录，无法提交保存数据！');
						return;
					}
					var vRecords = ds.getModifiedRecords();
					if( vRecords.length==0 ){
						Ext.MessageBox.alert('提示','无修改记录，请修改数据后再点击保存！');
						return;
					}
					Ext.MessageBox.confirm('确认对话框', '确认保存提交修改的数据？', 
				    	function(btn){
				    		if(btn=='yes'){
				    			batchSaveRecord();
				    		}
						});
				}},{xtype:'tbseparator'},
				{text:'删除配置',iconCls:'rec_delete',handler:function(gridPanel){
					if( ds.getCount()==0 ) {
						Ext.MessageBox.alert('提示','无记录，无法删除！');
						return;
					}
					var records = sm.getSelections();
					if( records.length==0 ) {
						Ext.MessageBox.alert('提示','未选择记录，无法删除！');
						return;
					}
					Ext.MessageBox.confirm('确认对话框', '确认删除选中记录吗？', function(btn){
			    		if(btn=='yes'){
			    			delRecords(records);
			    		}
					});
				}},{xtype:'tbseparator'},
				{text:'上传配置',iconCls:'rec_upload',handler:function(){
					uploadFormWindow.show();
				}},{xtype:'tbseparator'},
				{text:'发布更改',iconCls:'rec_publish',handler:function(){
					Ext.MessageBox.confirm('确认对话框', '确认发布通知所有服务器更新配置？', function(btn){
	    				if(btn=='yes'){
	    					processFlag = true;
	    					showWaitingBar();
	    					Ext.Ajax.request({// 排列顺序
								url : '/notifyRefresh',
								method : 'GET',
								success : function(response,action) {
									processFlag = false;
									Ext.MessageBox.hide();
									var responseArray = Ext.util.JSON.decode(response.responseText);
									if( responseArray.respMsg!=null ){
										Ext.MessageBox.alert('提示框',responseArray.respMsg);
									}
								},
								failure : processFailure
							});
	    				}
					});
				}},{text:'获取变动记录',iconCls:'rec_upload',handler:function(){
					changeRecordFormWindow.show();
				}},{xtype:'tbseparator'},
				],
			bbar : new Ext.PagingToolbar({
				pageSize: 50,
				store: ds,
				displayInfo: true,
				displayMsg: '第{0} 到 {1} 条数据 共{2}条',
				emptyMsg: '未查询到资源'
			})
	});
	//加载数据
	ds.load({params:{start:0, limit:50}});
	ds.on('beforeload',function(){ 
	 		Ext.apply(this.baseParams,{envType:Ext.get('envType').dom.value,
	 			appId:Ext.get('appId').dom.value,version:Ext.get('version').dom.value,
	 			configKey:Ext.get('configKey').dom.value,configValue:Ext.get('configValue').dom.value}
	  	);
	});
}

// 创建活动内容面板
function createContentPanel(){
	this.contentPanel = new Ext.Panel({
		split : true,
		bodyStyle : "width:100%",
		region : 'center',
		layout:'fit',
		margins : '0 0 0 0',
		forceFit : true,
		stripeRows : true,
	    enableTextSelection : true 
	});
}

//页面初始化
function init(){
	// 创建对象
	this.createContentPanel();
	this.createGridPanel();
	this.contentPanel.add(this.gridPanel);
	//carete add config window and form
	this.createConfigFormWindow();
	this.createConfigFormPanel();
	this.configFormWindow.add(this.configFormPanel);
	
	//carete add config window and form
	this.createBatchAddFormWindow();
	this.createBatchAddFormPanel();
	this.batchAddFormWindow.add(this.batchAddFormPanel);
	
	//carete add upload window and form
	this.createUploadFormWindow();
	this.createUploadFormPanel();
	this.uploadFormWindow.add(this.uploadFormPanel);
	
	//create change log window and form
	this.createChangeRecordFormWindow();
	this.createChangeRecordFormPanel();
	this.changeRecordFormWindow.add(this.changeRecordFormPanel);
	
	//布局管理器
	this.viewport = new Ext.Viewport({
			layout:'border',
			border:true,
			items:[this.contentPanel]
	});
	this.viewport.render();
}

//删除选中的
function delRecords(records){
	var configIds = new Array();
	var index = 0;
	for( var i=0;i<records.length;i++ ){
		configIds.push(records[i].get('configId'));
	}
	if( configIds.length==0 ){
		processFlag = false;
		return;
	}
	processFlag = true;
	this.showWaitingBar();
	Ext.Ajax.request({// 排列顺序
		url : systemContext + '/appconfig/deleteConfigRecords',
		params : {
			configIds : configIds
		},
		method : 'POST',
		success : function(response,action) {
			processFlag = false;
			var responseArray = Ext.util.JSON.decode(response.responseText);
			Ext.MessageBox.alert('提示框',responseArray.respMsg);
			gridPanel.getStore().load({
				params:{start:0, limit:50}
			});
		},
		failure : processFailure
	});
}

//批量保存数据
function batchSaveRecord(){
	var vRecords = gridPanel.getStore().getModifiedRecords(); //得到修改的数据（记录对象）
	var vCount = vRecords.length; //得到记录长度
	if (vCount > 0) {
        //begin 将记录对象转换为字符串（json格式的字符串）
        var vDatas = '[';
        for (var i = 0; i < vCount; i++) {
            vDatas += Ext.util.JSON.encode(vRecords[i].data) + ',';
        }
        vDatas = vDatas.substr(0, vDatas.length - 1) + ']';
        processFlag = true;
        this.showWaitingBar();
        Ext.Ajax.request({// 排列顺序
    		url : '/appconfig/batchSaveConfigRecord',
    		method : 'POST',
    		params: {datas: vDatas},
    		success : function(response,action) {
    			processFlag = false;
    			var responseArray = Ext.util.JSON.decode(response.responseText);
    			if( responseArray.respMsg!=null ){
    				Ext.MessageBox.alert('提示框',responseArray.respMsg);
    			}
    			if( responseArray.success){
    				gridPanel.getStore().commitChanges();
    				gridPanel.getStore().load({
    					params:{start:0, limit:50}
    				});
    			}
    		},
    		failure : processFailure
    	});
    }
}

//创建用户窗口面板
function createConfigFormWindow(){
	configFormWindow = new Ext.Window({
				title : '添加配置信息',
				id : 'configFormWindow',
                layout:'fit',
                width:390,
                height:380,
                closeAction:'hide',
                plain: true,
                modal:true,
                collapsible: false,
                maximizable:false,
                draggable: true,
                closable: false,
                resizable:false,
                animateTarget:document.body
			});
}
//创建用户表单面板
function createConfigFormPanel(){
	configFormPanel = new Ext.FormPanel({
		labelWidth : 90,
		labelAlign:'right',
		id:'configFormPanel',
		frame : true,
		border:false,
		bodyStyle : 'padding:0px 0px 0',
		defaultType : 'textfield',
		items : [{
			xtype : 'combo',
			fieldLabel: '环境',
			store : dataStore,
			displayField : 'name',
			valueField : 'code',
			typeAhead : true,
			mode : 'remote',
			triggerAction : 'all',
			emptyText : '请选环境...',
			selectOnFocus : true,
			allowBlank: false,
			resizable : true,
			hiddenName : 'envType',
		},{
			xtype : 'combo',
			fieldLabel: '应用',
			store : projectDataStore1,
			displayField : 'name',
			valueField : 'code',
			typeAhead : true,
			mode : 'remote',
			triggerAction : 'all',
			emptyText : '请选应用...',
			selectOnFocus : true,
			allowBlank: false,
			resizable : true,
			hiddenName : 'appId',
			listeners:{
				focus:function(combo,record,index){
					var envType = configFormPanel.getForm().findField('envType').getValue();
					console.log(envType);
					projectDataStore1.load({params:{envType: envType}});
	            }
	        }
		},{
        	fieldLabel: '配置键值',
		    name: 'configKey',   
		    maxLength:'80',
			minLength:'3',
			width: 200,
			allowBlank: false,
            blankText: '键值不能为空',
		    minLengthText: '键值长度必须在6到16位之间',
		    maxLengthText: '键值长度必须在6到16位之间'
   	 	},{
			allowBlank: false,  
		    name: 'configValue', 
		    width: 200,
		    fieldLabel: '配置值',
            blankText: '配置值不能为空'
   	 	},{
			allowBlank: true,  
		    name: 'ip', 
		    width: 200,
		    fieldLabel: '服务器IP',
		    validator : function(value) {  
		    	var reg = /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
		        if(value == ''){
		        	return true;
		        }
		        if(reg.test(value)){  
		            return true;  
		        }else{
		        	return "ip地址不合法";
		        }
		        return true;  
		    } 
   	 	},new Ext.form.ComboBox({
		    store: new Ext.data.SimpleStore({
			    fields: ['returnValue', 'displayValue'],
			    data : [['S','系统'], ['B','业务']]
			}),
		    displayField:'displayValue',
		    valueField:'returnValue',
		    typeAhead: true,
		    mode: 'local',
		    editable:false,
		    hiddenName:'type',
		    fieldLabel: '类型',
			width:100,
		    triggerAction: 'all',
		    emptyText:'全部',
		    selectOnFocus:true,
		    allowBlank: false, 
			name : 'type'
		}),new Ext.form.Checkbox({
   	 		 fieldLabel: '是否加密',
   	 		 allowBlank: true, 
			 name : "isEncrypt",
			 value: "1"
   	 	}),{
   	 		width: 200,
			allowBlank: true,  
		    name: 'memo', 
		    fieldLabel: '备注描述'
   	 	}],
		buttons : [{
			text : '保存',
			handler:function(){
				var configForm = configFormPanel.getForm();
				if( configForm.isValid() ){
					saveAddConfig(configForm);
				}
			}
		}, {
			text : '取消',
			handler:function(){
				configFormWindow.hide();
			}
		}]
	});
}
function saveAddConfig(form){
	form.submit({
		url : '/appconfig/save',
		method : 'POST',
		success : function(from, action) {
			if( action.result.code==0 ){
				configFormWindow.hide();
				configFormPanel.getForm().reset();
			}
			Ext.MessageBox.alert('提示框',action.result.msg);
			gridPanel.getStore().load({
				params:{start:0, limit:50}
			});
		},
		failure : processFailure,
		waitMsg : '正在保存数据，稍后...',
		waitTitle:'提示'
	});
}

//创建上传窗口面板
function createUploadFormWindow(){
	uploadFormWindow = new Ext.Window({
				title : '上传配置信息',
				id : 'uploadFormWindow',
                layout:'fit',
                width:470,
                height:240,
                closeAction:'hide',
                plain: true,
                modal:true,
                collapsible: false,
                maximizable:false,
                draggable: true,
                closable: false,
                resizable:false,
                animateTarget:document.body
			});
}
//创建上传表单面板
function createUploadFormPanel(){
	uploadFormPanel = new Ext.FormPanel({
		labelWidth : 140,
		labelAlign:'right',
		id:'uploadFormPanel',
		frame : true,
		border:false,
		bodyStyle : 'padding:0px 0px 0',
		defaultType : 'textfield',
		fileUpload: true,
		enctype:'multipart/form-data',
		items : [{
			xtype : 'combo',
			fieldLabel: '环境',
			store : dataStore1,
			displayField : 'name',
			valueField : 'code',
			typeAhead : true,
			mode : 'remote',
			triggerAction : 'all',
			emptyText : '请选环境...',
			selectOnFocus : true,
			allowBlank: false,
			resizable : true,
			hiddenName : 'envType',
			listeners:{
				select:function(combo,record,index){
					var envType = combo.getValue();
					console.log(envType);
					projectDataStore1.load({params:{envType: envType}});
	            }
	        }
		},{
			xtype : 'combo',
			fieldLabel: '应用',
			store : projectDataStore1,
			displayField : 'name',
			valueField : 'code',
			typeAhead : true,
			mode : 'remote',
			triggerAction : 'all',
			emptyText : '请选应用...',
			selectOnFocus : true,
			allowBlank: false,
			resizable : true,
			hiddenName : 'appId',
			listeners:{
				focus:function(combo,record,index){
					var envType = uploadFormPanel.getForm().findField('envType').getValue();
					console.log(envType);
					projectDataStore1.load({params:{envType: envType}});
	            }
	        }
		},{
        	xtype :'checkbox',
        	fieldLabel: '覆盖已有',
        	name :'overProp',
        	boxLabel : '是'
        },{
            fieldLabel: '配置源(yaml或prop文件)',
		    name: 'file',   
			allowBlank: false,
			blankText: '上传文件不能为空!',
			inputType : 'file',
			xtype:'textfield'
        }],
		buttons : [{
			text : '保存',
			handler:function(){
				var uploadForm = uploadFormPanel.getForm();
				if( uploadForm.isValid() ){
					saveUploadConfig(uploadForm);
				}
			}
		}, {
			text : '取消',
			handler:function(){
				uploadFormWindow.hide();
			}
		}]
	});
}
//获取最近变动记录
var changeRecordFormWindow;
var changeRecordFormPanel;
function createChangeRecordFormWindow(){
	changeRecordFormWindow = new Ext.Window({
				title : '获取变动配置信息',
				id : 'changeRecordFormWindow',
				layout:'fit',
                width:700,
                height:520,
                closeAction:'hide',
                plain: true,
                modal:true,
                collapsible: false,
                maximizable:false,
                draggable: true,
                closable: false,
                resizable:false,
                animateTarget:document.body
	});
}
//创建上传表单面板
function createChangeRecordFormPanel(){
	changeRecordFormPanel = new Ext.FormPanel({
		labelWidth : 90,
		labelAlign:'right',
		id:'changeRecordFormPanel',
		frame : true,
		border:false,
		bodyStyle : 'padding:0px 0px 0',
		defaultType : 'textfield',
		items : [{
			xtype : 'combo',
			fieldLabel: '环境',
			store : dataStore1,
			displayField : 'name',
			valueField : 'code',
			typeAhead : true,
			mode : 'remote',
			triggerAction : 'all',
			emptyText : '请选环境...',
			selectOnFocus : true,
			allowBlank: false,
			resizable : true,
			hiddenName : 'envType',
			listeners:{
				select:function(combo,record,index){
					var envType = combo.getValue();
					console.log(envType);
					projectDataStore1.load({params:{envType: envType}});
	            }
	        }
		},{
			xtype : 'combo',
			fieldLabel: '应用',
			store : projectDataStore1,
			displayField : 'name',
			valueField : 'code',
			typeAhead : true,
			mode : 'remote',
			triggerAction : 'all',
			emptyText : '请选应用...',
			selectOnFocus : true,
			allowBlank: false,
			resizable : true,
			hiddenName : 'appId',
			listeners:{
				focus:function(combo,record,index){
					var envType = changeRecordFormPanel.getForm().findField('envType').getValue();
					console.log(envType);
					projectDataStore1.load({params:{envType: envType}});
	            }
	        }
		},new Ext.form.DateField({
		    fieldLabel: '起始时间',
		    name: 'startDateTime',
		    format:'Y-m-d H:i:s',
		    anchor:'50%',
			msgTarget : 'side'
		}),new Ext.form.DateField({
		    fieldLabel: '结束时间',
		    name: 'endDateTime',
		    format:'Y-m-d H:i:s',
		    anchor:'50%',
			msgTarget : 'side'
		}),{
			xtype : 'combo',
			fieldLabel: '格式',
			store: new Ext.data.SimpleStore({
			    fields: ['returnValue', 'displayValue'],
			    data : [['','选择'],['properties','properties格式'],['yml','yml格式']]
			}),
			displayField:'displayValue',
		    valueField:'returnValue',
		    typeAhead: true,
		    mode: 'local',
		    editable:false,
		    hiddenName:'operateType',
			width:100,
		    triggerAction: 'all',
		    emptyText:'全部',
		    selectOnFocus:true,
		    fieldLabel : '操作类型',
			name : 'exportFormart',
			hiddenName : 'exportFormart'
		},new Ext.form.Checkbox({
   	 		 fieldLabel: '包括所有',
   	 		 allowBlank: true, 
   	 		 checked: true,
			 name : "includeAll",
			 value: "1"
   	 	}),{
			xtype : 'textarea',
        	fieldLabel: '配置键值',
		    name: 'configKeys',   
			width: 550,
			height: 300,
   	 	}],
		buttons : [{
			text : '获取',
			handler:function(){
				var form = changeRecordFormPanel.getForm();
				if( form.isValid() ){
					form.submit({
						url : '/appconfig/getLatestChangeLogs',
						method : 'POST',
						success : function(from, action) {
							Ext.MessageBox.alert('提示框',action.result.msg);
							var configKeys = changeRecordFormPanel.getForm().findField('configKeys');
							configKeys.setValue(action.result.data);
						},
						failure : processFailure,
						waitMsg : '正在获取数据，稍后...',
						waitTitle:'提示'
					});
				}
			}
		}, {
			text : '关闭',
			handler:function(){
				changeRecordFormWindow.hide();
			}
		}]
	});
}
function saveUploadConfig(form){
	form.submit({
		url : '/appconfig/saveUploadConfigFile',
		method : 'POST',
		enctype:'multipart/form-data',
		fileUpload: true,
		success : function(from, action) {
			if( action.success ){
				uploadFormWindow.hide();
				uploadFormPanel.getForm().reset();
			}
			Ext.MessageBox.alert('提示框',action.result.respMsg);
			gridPanel.getStore().load({
				params:{start:0, limit:50}
			});
		},
		failure : processFailure,
		waitMsg : '正在保存数据，稍后...',
		waitTitle:'提示'
	});
}

//创建用户窗口面板
function createBatchAddFormWindow(){
	batchAddFormWindow = new Ext.Window({
				title : '批量添加配置信息',
				id : 'batchAddFormWindow',
                layout:'fit',
                width:650,
                height:500,
                closeAction:'hide',
                plain: true,
                modal:true,
                collapsible: false,
                maximizable:false,
                draggable: true,
                closable: false,
                resizable:false,
                animateTarget:document.body
			});
}
//创建用户表单面板
function createBatchAddFormPanel(){
	batchAddFormPanel = new Ext.FormPanel({
		labelWidth : 140,
		labelAlign:'right',
		id:'batchAddFormPanel',
		frame : true,
		border:false,
		bodyStyle : 'padding:0px 0px 0',
		defaultType : 'textfield',
		items : [{
			xtype : 'combo',
			fieldLabel: '应用',
			store : projectDataStore1,
			displayField : 'name',
			valueField : 'code',
			typeAhead : true,
			mode : 'remote',
			triggerAction : 'all',
			emptyText : '请选应用...',
			selectOnFocus : true,
			allowBlank: false,
			resizable : true,
			hiddenName : 'appId',
		},{
			xtype : 'textarea',
        	fieldLabel: '配置键值(pro或yml格式)',
		    name: 'configKeys',   
			width: 450,
			height: 300,
			allowBlank: false
   	 	},{
        	xtype :'checkbox',
        	fieldLabel: '覆盖已有',
        	name :'overProp',
        	boxLabel : '是'
        },{
   	 		width: 200,
			allowBlank: true,  
		    name: 'memo', 
		    fieldLabel: '备注描述',
		    value:'批量添加'
   	 	}],
		buttons : [{
			text : '保存',
			handler:function(){
				var configForm = batchAddFormPanel.getForm();
				if( configForm.isValid() ){
					saveBatchAddConfig(configForm);
				}
			}
		}, {
			text : '取消',
			handler:function(){
				batchAddFormWindow.hide();
			}
		}]
	});
}
function saveBatchAddConfig(form){
	form.submit({
		url : '/appconfig/saveBatchAddConfig',
		method : 'POST',
		success : function(from, action) {
			if( action.result.success ){
				batchAddFormWindow.hide();
				batchAddFormPanel.getForm().reset();
			}
			Ext.MessageBox.alert('提示框',action.result.msg);
			gridPanel.getStore().load({
				params:{start:0, limit:50}
			});
		},
		failure : processFailure,
		waitMsg : '正在保存数据，稍后...',
		waitTitle:'提示'
	});
}